import { type ReactNode } from "react";
import { Navigate } from "react-router-dom";

import Lazy from "@/router/components/Lazy";
interface MetaProps {
	title: string;
}

export interface RouteObject {
	children?: RouteObject[];
	element?: ReactNode;
	path?: string;
	name?: string;
	meta?: MetaProps;
}

// const routeModules = import.meta.glob("./modules/*.tsx", { eager: true }) as any;
// const routeList = Object.keys(routeModules).reduce((cur, item) => {
// 	Object.keys(routeModules[item]).forEach(v => {
// 		cur.push(...routeModules[item][v]);
// 	});
// 	return cur;
// }, [] as RouteObject[]);

// const asyncRoutes: RouteObject[] = [
//   {
//     element: <Layout />,
//     children: [...routeList]
//   }
// ];

const baseRoute = [
	{
		path: "/",
		element: <Navigate to="/home" replace={true} />
	},
	{
		path: "/home",
		element: <Lazy module={() => import("@/pages/Home")} />
	},
	{
		path: "/404",
		name: "404",
		element: <Lazy module={() => import("@/pages/404")} />
	},
	{
		path: "*",
		element: <Navigate to="/404" replace={true} />
	}
] as const;

export type TPath = (typeof baseRoute)[number]["path"];

export const routes = [...baseRoute];

export const whiteList = ["login", "404"];
